﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DiscoveryLogic.UI.Layouts.Controls
{
    public partial class VideoPlayer : UserControl
    {
        #region Private Methods

            protected void OnDownloaderCompleted(object sender, EventArgs e)
            {

            }


            void OnPlayMouseLeftButtonDown(object sender, MouseEventArgs e)
            {
                if (Play != null)
                {
                    Play(this, e);
                }
                
                if (mainMediaElement.CurrentState.Equals("Stopped"))
                {
                    mainMediaElement.Play();
                }
                else if (mainMediaElement.CurrentState.Equals("Playing"))
                {
                    mainMediaElement.Pause();
                }
                else if (!mainMediaElement.CurrentState.Equals("Playing"))
                {
                    mainMediaElement.Play();
                }

            }

            void OnCloseMouseLeftButtonDown(object sender, MouseEventArgs e)
            {
                if (Close != null)
                {
                    Close(sender, null);
                }
                this.Flyback();
                
                mainMediaElement.Stop();
            }

        #endregion Private Methods

        #region Public Properties

            private FrameworkElement control;

            public FrameworkElement Control
            {
                get
                {
                    return control;
                }
                set
                {
                    control = value;
                }
            }

        #endregion Public Properties

        #region Public Events

            public event EventHandler Close;
            public event EventHandler Open;
            public event EventHandler Play;

        #endregion Public Events

        #region Public Methods

            public void Flyout()
            {            
                VideoFlyout.Begin();
            }

            public void Flyback()
            {
                VideoFlyback.Begin();
            }

        #endregion Public Methods

        #region Constructors

            public VideoPlayer()
            {
                try
                {
                    InitializeComponent();
                    control = Root;
                }
                catch (Exception ex)
                {
                    string err = ex.Message;
                }

                Canvas closeButton = CloseBut;
                closeButton.MouseLeftButtonDown += new MouseButtonEventHandler(OnCloseMouseLeftButtonDown);

                Canvas playButton = PlayBut;
                playButton.MouseLeftButtonDown += new MouseButtonEventHandler(OnPlayMouseLeftButtonDown);

            }

        #endregion Constructors
    }
}
